﻿/**
 * File:   sonar_view.h
 * Author: 
 * Brief:  
 *
 * Copyright (c) 2024 - 2024 
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * License file for more details.
 *
 */

/**
 * History:
 * ================================================================
 * 2024-8-18  created
 *
 */


#ifndef TK_SONAR_VIEW_H
#define TK_SONAR_VIEW_H

#include "base/widget.h"

BEGIN_C_DECLS
/**
 * @class sonar_view_t
 * @parent widget_t
 * @annotation ["scriptable","design","widget"]
 * 
 * 在xml中使用"sonar\_view"标签创建控件。如：
 *
 * ```xml
 * <!-- ui -->
 * <sonar_view name="sonar_view" x="303" y="193" w="332" h="134" children_layout="default(c=3,r=1,s=1)">
    <button name="view1" style:normal:border_color="#FF0000" style:normal:bg_color="#FF0000" focusable="true" style:focused:bg_color="#FF0000" style:focused:border_color="#00FFFF" text="Button"/>
    <button name="view2" style:normal:border_color="#FFC000" style:normal:bg_color="#FFC000" focusable="true" style:focused:bg_color="#FFC000" style:focused:border_color="#00FFFF" text="Button"/>
    <button name="view3" style:normal:border_color="#002060" style:normal:bg_color="#002060" focusable="true" style:focused:bg_color="#002060" style:focused:border_color="#00FFFF" text="Button"/>
  </sonar_view>
 * ```
 *
 * 可用通过style来设置控件的显示风格，如字体的大小和颜色等等。如：
 * 
 * ```xml
 * <!-- style -->
 * <sonar_view>
 *   <style name="default" font_size="32">
 *     <normal text_color="black" />
 *   </style>
 * </sonar_view>
 * ```
 */
typedef struct _sonar_view_t {
  widget_t widget;

  bool_t inited;
} sonar_view_t;

/**
 * @method sonar_view_create
 * @annotation ["constructor", "scriptable"]
 * 创建sonar_view对象
 * @param {widget_t*} parent 父控件
 * @param {xy_t} x x坐标
 * @param {xy_t} y y坐标
 * @param {wh_t} w 宽度
 * @param {wh_t} h 高度
 *
 * @return {widget_t*} sonar_view对象。
 */
widget_t* sonar_view_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h);

/**
 * @method sonar_view_cast
 * 转换为sonar_view对象(供脚本语言使用)。
 * @annotation ["cast", "scriptable"]
 * @param {widget_t*} widget sonar_view对象。
 *
 * @return {widget_t*} sonar_view对象。
 */
widget_t* sonar_view_cast(widget_t* widget);



#define SONAR_VIEW_SUB_WIDGET_VIEW1 "view1"
#define SONAR_VIEW_SUB_WIDGET_VIEW2 "view2"
#define SONAR_VIEW_SUB_WIDGET_VIEW3 "view3"

#define WIDGET_TYPE_SONAR_VIEW "sonar_view"

#define SONAR_VIEW(widget) ((sonar_view_t*)(sonar_view_cast(WIDGET(widget))))

/*public for subclass and runtime type check*/
TK_EXTERN_VTABLE(sonar_view);

END_C_DECLS

#endif /*TK_SONAR_VIEW_H*/
